﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

/// <summary>
/// Summary description for Class1
/// </summary>
public class Logger
{
    private static Logger instance;
    public static Logger getInstance()
    {
        if (instance == null)
        {
            instance = new Logger("cinema.log");
			instance.Open();
        }

        return instance;
    }

    private string _logPath;
    private StreamWriter stream;
    
    private Logger( string logPath = null )
	{
        _logPath = logPath;
	}

    public string logPath
    {
        get { return _logPath; }
        set { _logPath = value; }
    }

    public void Open()
    {
        if (_logPath == null)
        {
            throw new Exception("Logger: Attempt to open an invalid path!");
        }
        stream = new StreamWriter(_logPath);
    }

    public void Close()
    {
        stream.Close();
    }

    public void LogMessage(string message)
    {
        if (stream == null)
        {
            throw new Exception("Logger: Attempt to write a null stream!");
        }
        DateTime dateTime = new DateTime();
        stream.WriteLine(dateTime.Day.ToString() + "/" +
                            dateTime.Month.ToString() + "/" +
                            dateTime.Year.ToString() + " " +
                            dateTime.Hour.ToString() + ":" +
                            dateTime.Minute.ToString() + " => " +
                            message);
    }
}